using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
public class MBFWebserviceMember : Member
{
	private static MBFWebserviceMember _instance = null;
	public static MBFWebserviceMember instance
	{
		get
		{
			if (MBFWebserviceMember._instance == null)
			{
				MBFWebserviceMember._instance = new MBFWebserviceMember();
			}
			return MBFWebserviceMember._instance;
		}
	}
	private MBFWebserviceMember()
	{
	}
	public void GetCardInfo(HttpContext context)
	{
		string text = context.Request.Params["PayTypeID"].IsNull(new object[0]).Trim();
		int num;
		if (text == "")
		{
			num = 1;
		}
		else
		{
			num = text.ToInt32(new int[0]);
		}
		DataTable dataTable = null;
		switch (num)
		{
		case -2:
			dataTable = Blls.bllGiftCard.GetList(string.Concat(new object[]
			{
				" Balance >0 and recieveid=",
				base.user.UserID,
				" or (BuyID=",
				base.user.UserID,
				" and(recieveid=0 or recieveid is null))"
			})).Tables[0];
			break;
		case -1:
			dataTable = Blls.bllUserVipCard.GetList("PurchaseUserID=" + base.user.UserID + " and Balance>0 ").Tables[0];
			break;
		}
		if (dataTable != null)
		{
			context.Response.Write(dataTable.DataTableToJson());
		}
		else
		{
			context.Response.Write("");
		}
	}
	public void GetCardBalance(HttpContext context)
	{
		string text = context.Request.Params["PayTypeID"].IsNull(new object[0]).Trim();
		int cardType;
		if (text == "")
		{
			cardType = 1;
		}
		else
		{
			cardType = text.ToInt32(new int[0]);
		}
		string s = "";
		decimal cardBalance = this.GetCardBalance(cardType);
		switch (cardType)
		{
		case -3:
			s = string.Format("您的中奖券可用余额为：{0}", cardBalance);
			break;
		case -2:
			s = string.Format("您的礼品卡可用余额为：{0}", cardBalance);
			break;
		case -1:
			s = string.Format("您的VIP卡可用余额为：{0}", cardBalance);
			break;
		case 0:
			s = string.Format("您的商城帐户可用余额为：{0}", cardBalance);
			break;
		}
		context.Response.Write(s);
	}
	public decimal GetCardBalance(int CardType)
	{
		decimal result = 0.00m;
		switch (CardType)
		{
		case -3:
			result = Conn.GetSingle("select sum(Balance) from MBF_UserLotteryCard where UserID=" + base.user.UserID + " and datediff(dd,EffectiveTime,GetDate())<=0  and IsDeleted=0", new IDbDataParameter[0]).IsNull(new object[0]).ToDecimal2();
			break;
		case -2:
			result = Conn.GetSingle(string.Concat(new object[]
			{
				"select sum(Balance) from MBF_UserGiftCard where recieveid=",
				base.user.UserID,
				" or (BuyID=",
				base.user.UserID,
				" and(recieveid=0 or recieveid is null))"
			}), new IDbDataParameter[0]).IsNull(new object[0]).ToDecimal2();
			break;
		case -1:
			result = Conn.GetSingle("select sum(Balance) from MBF_UserVipCard where PurchaseUserID=" + base.user.UserID, new IDbDataParameter[0]).IsNull(new object[0]).ToDecimal2();
			break;
		case 0:
			result = Conn.GetSingle("select Balance from HL_User where UserID=" + base.user.UserID, new IDbDataParameter[0]).IsNull(new object[0]).ToDecimal2();
			break;
		}
		return result;
	}
	public void GetGiftValuesByFestivalName(HttpContext context)
	{
		string text = context.Request.Params["festivalname"].Trim();
		if (text != "")
		{
			string text2 = "";
			DataTable dataTable = Conn.Query("select FaceValue,DiscountRate from MBF_UserGiftCardFaceValue where FestivalName=@FestivalName", new IDbDataParameter[]
			{
				new SqlParameter("FestivalName", text)
			}).Tables[0];
			if (dataTable != null && dataTable.Rows.Count > 0)
			{
				foreach (DataRow dataRow in dataTable.Rows)
				{
					object obj = text2;
					text2 = string.Concat(new object[]
					{
						obj,
						dataRow["FaceValue"],
						"_",
						dataRow["DiscountRate"],
						","
					});
				}
			}
			text2 = text2.Trim(new char[]
			{
				','
			});
			context.Response.Write(text2);
		}
		else
		{
			context.Response.Write("");
		}
	}
	public void GetUserIDByUserName(HttpContext context)
	{
		string text = context.Request.Params["username"].Trim();
		if (text != "")
		{
			string text2 = Conn.GetSingle("select Top 1 UserID from HL_User where UserName=@UserName", new IDbDataParameter[]
			{
				new SqlParameter("UserName", text)
			}).IsNull(new object[0]);
			if (text2 == base.user.UserID.ToString())
			{
				context.Response.Write("isself");
			}
			else
			{
				context.Response.Write(text2);
			}
		}
		else
		{
			context.Response.Write("");
		}
	}
}
